package com.huawei.appmarket.service.appmgr.view.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.MaskImageView;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appmarket.service.appmgr.bean.ApkInstalledInfo;
import com.huawei.appmarket.service.appmgr.view.widget.InstallButton;
import com.huawei.appmarket.service.appmgr.view.widget.InstallButton.InstallCardBean;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.huawei.hwid.core.constants.HwAccountConstants;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import o.azb;
import o.bla;
import o.cdb;
import o.cdf;
import o.ced;
import o.cep;
import o.cke;
import o.BaseAlertDialog;
import o.cnw;
import o.cnz;
import o.coa;
import o.coe;
import o.dgh;
import o.dgm;
import o.dkb;
import o.dky;
import o.Logger;
import o.dof;
import o.dok;
import o.ContentManager;
import o.dsv;
import o.dtb;
import o.dtg;
import o.dtm;
import o.dvq;
import o.dvt;
import o.dwa;
import o.dwq;
import o.epv;
import o.epw;
import o.CollectCheck;
import o.eqh;
import o.eqp;
import o.eqx;
import o.erm;
import o.erw;
import o.etn;
import o.euf;
import o.NetWorkUtil;
import o.evk;
import o.evy;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.fho;
import o.fhz;
import o.ll;

@SuppressLint({"InflateParams"})
public class InstalledListAdapter extends BaseAdapter implements OnClickListener {
    private static final int INSTALLED_TITLE_TYPE = 2;
    private static final int INSTALLED_TYPE = 3;
    private static final int INSTALLING_TITLE_TYPE = 0;
    private static final int INSTALLING_TYPE = 1;
    private static final String TAG = "InstalledListAdapter";
    private static final int UNINSTALL_BUTTON_SHOW_RATIO = 2;
    private int compoundPadding;
    private BaseAlertDialog dlg = null;
    private List<SessionDownloadTask> downloading = new ArrayList();
    private View emptyView = null;
    private int expandItemType = -1;
    private String expandPackageName = "";
    private final String homeCountry = eqp.ॱ();
    private d iSelectAppAction;
    private List<SessionDownloadTask> installing = new ArrayList();
    private Context mActivity = null;
    private coa mPackageState;
    private List<ApkInstalledInfo> requestInstalled = new ArrayList();
    private final String shaUserId = UserSession.getInstance().getUserId();
    private boolean supportBatchUninstall;
    private ColorDrawable transparentDrawable;

    static class a {
        private View ʻ;
        private LinearLayout ʼ;
        private LinearLayout ʽ;
        private LinearLayout ˊ;
        private View ˊॱ;
        private TextView ˋ;
        private View ˋॱ;
        private RelativeLayout ˎ;
        private MaskImageView ˏ;
        private DownloadButton ˏॱ;
        private TextView ͺ;
        private HwButton ॱ;
        private TextView ॱˊ;
        private View ॱॱ;
        private TextView ᐝ;

        private a() {
        }

        public MaskImageView ॱ() {
            return this.ˏ;
        }

        public void ˎ(MaskImageView maskImageView) {
            this.ˏ = maskImageView;
        }

        public TextView ˊ() {
            return this.ˋ;
        }

        public void ˊ(TextView textView) {
            this.ˋ = textView;
        }

        public RelativeLayout ˋ() {
            return this.ˎ;
        }

        public void ˏ(RelativeLayout relativeLayout) {
            this.ˎ = relativeLayout;
        }

        public LinearLayout ˎ() {
            return this.ˊ;
        }

        public void ˊ(LinearLayout linearLayout) {
            this.ˊ = linearLayout;
        }

        public TextView ˏ() {
            return this.ॱ;
        }

        public void ॱ(HwButton hwButton) {
            this.ॱ = hwButton;
        }

        public View ʽ() {
            return this.ʻ;
        }

        public void ˏ(View view) {
            this.ʻ = view;
        }

        public View ʻ() {
            return this.ॱॱ;
        }

        public void ॱ(View view) {
            this.ॱॱ = view;
        }

        public LinearLayout ᐝ() {
            return this.ʼ;
        }

        public void ˎ(LinearLayout linearLayout) {
            this.ʼ = linearLayout;
        }

        public LinearLayout ॱॱ() {
            return this.ʽ;
        }

        public void ॱ(LinearLayout linearLayout) {
            this.ʽ = linearLayout;
        }

        public TextView ʼ() {
            return this.ᐝ;
        }

        public void ॱ(TextView textView) {
            this.ᐝ = textView;
        }

        public TextView ॱˊ() {
            return this.ॱˊ;
        }

        public void ˎ(TextView textView) {
            this.ॱˊ = textView;
        }

        public TextView ˊॱ() {
            return this.ͺ;
        }

        public void ˏ(TextView textView) {
            this.ͺ = textView;
        }

        public View ˋॱ() {
            return this.ˋॱ;
        }

        public void ˋ(View view) {
            this.ˋॱ = view;
        }

        public View ͺ() {
            return this.ˊॱ;
        }

        public void ˎ(View view) {
            this.ˊॱ = view;
        }

        public DownloadButton ˏॱ() {
            return this.ˏॱ;
        }

        public void ˋ(DownloadButton downloadButton) {
            this.ˏॱ = downloadButton;
        }
    }

    class b extends evy {
        final /* synthetic */ InstalledListAdapter ॱ;

        private b(InstalledListAdapter installedListAdapter) {
            this.ॱ = installedListAdapter;
        }

        public void ˎ(View view) {
            if (dtb.ॱ().ˎ()) {
                dtb.ॱ().ˋ();
                dgh.ॱ(ContentManager.getInstant().getContext(), "070606", "04|" + this.ॱ.shaUserId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ॱ.homeCountry);
                return;
            }
            if (dtb.ॱ().ʼ()) {
                dgh.ॱ(ContentManager.getInstant().getContext(), "070606", "07|" + this.ॱ.shaUserId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ॱ.homeCountry);
            } else {
                dgh.ॱ(ContentManager.getInstant().getContext(), "070606", "05|" + this.ॱ.shaUserId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ॱ.homeCountry);
            }
            if (dok.ͺ()) {
                dtb.ॱ().ˊ(view.getContext());
            } else {
                evk.ˋ(ContentManager.getInstant().getContext(), ContentManager.getInstant().getContext().getString(n.ʹˊ), 0).ˋ();
            }
        }
    }

    public static class c {
        private InstallButton ʽ;
        private HwButton ˊ;
        private LinearLayout ˋ;
        private LinearLayout ˎ;
        private dtm ˏ = new dtm();
        private HwButton ॱ;
        private View ॱॱ;
        private View ᐝ;

        public LinearLayout ॱ() {
            return this.ˎ;
        }

        public void ˊ(LinearLayout linearLayout) {
            this.ˎ = linearLayout;
        }

        public dtm ˊ() {
            return this.ˏ;
        }

        public TextView ˋ() {
            return this.ˊ;
        }

        public void ˏ(HwButton hwButton) {
            this.ˊ = hwButton;
        }

        public TextView ˏ() {
            return this.ॱ;
        }

        public void ˋ(HwButton hwButton) {
            this.ॱ = hwButton;
        }

        public LinearLayout ˎ() {
            return this.ˋ;
        }

        public void ˏ(LinearLayout linearLayout) {
            this.ˋ = linearLayout;
        }

        public InstallButton ᐝ() {
            return this.ʽ;
        }

        public void ॱ(InstallButton installButton) {
            this.ʽ = installButton;
        }

        public View ʼ() {
            return this.ॱॱ;
        }

        public void ˎ(View view) {
            this.ॱॱ = view;
        }

        public View ʽ() {
            return this.ᐝ;
        }

        public void ˏ(View view) {
            this.ᐝ = view;
        }
    }

    public interface d {
        void ˎ(String str, long j);
    }

    static class e {
        public TextView ˊ;

        private e() {
        }
    }

    public InstalledListAdapter(Context context, View view) {
        this.mActivity = context;
        this.emptyView = view;
        this.transparentDrawable = new ColorDrawable(context.getResources().getColor(o.ewm.c.ˉ));
        this.transparentDrawable.setBounds(0, 0, 0, 0);
        this.compoundPadding = context.getResources().getDimensionPixelSize(o.ewm.d.ꓸ);
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (ˋ != null) {
            this.mPackageState = (coa) ˋ.ॱ(coa.class);
        }
    }

    public void setISelectAppAction(d dVar) {
        this.iSelectAppAction = dVar;
    }

    public void setSupportBatchUninstall(boolean z) {
        this.supportBatchUninstall = z;
    }

    public void setData(List<ApkInstalledInfo> list, o.dtb.d dVar) {
        setDatas(list, dVar);
        notifyDataSetChanged();
    }

    public void setDatas(List<ApkInstalledInfo> list, o.dtb.d dVar) {
        this.requestInstalled.clear();
        this.requestInstalled.addAll(list);
        Collections.sort(this.requestInstalled, new dtg());
        this.downloading.clear();
        this.downloading.addAll(dVar.ˎ());
        this.installing.clear();
        this.installing.addAll(dVar.ॱ());
        addGameUpgradeTask(this.installing, dtb.ॱ().ˊ());
        if (this.requestInstalled.isEmpty() && this.downloading.isEmpty() && this.installing.isEmpty()) {
            this.emptyView.setVisibility(0);
        } else {
            this.emptyView.setVisibility(8);
        }
    }

    private void addGameUpgradeTask(List<SessionDownloadTask> list, List<SessionDownloadTask> list2) {
        for (SessionDownloadTask sessionDownloadTask : list2) {
            Object obj;
            for (SessionDownloadTask ˊˊ : list) {
                if (ˊˊ.ˊˊ().equals(sessionDownloadTask.ˊˊ())) {
                    obj = 1;
                    break;
                }
            }
            obj = null;
            if (obj == null) {
                list.add(sessionDownloadTask);
            }
        }
    }

    public String getExpandPackageName(int i) {
        if (this.expandItemType == i) {
            return this.expandPackageName;
        }
        return "";
    }

    public void setExpandPackageName(int i, String str) {
        this.expandItemType = i;
        this.expandPackageName = str;
    }

    public boolean isEnabled(int i) {
        if (i == 0) {
            return false;
        }
        if (this.installing.size() + this.downloading.size() <= 0 || i != (this.installing.size() + this.downloading.size()) + 1) {
            return true;
        }
        return false;
    }

    public int getItemViewType(int i) {
        int size = this.installing.size() + this.downloading.size();
        if (size > 0) {
            size = i - size;
            if (size > 1) {
                return 3;
            }
            if (size == 1) {
                return 2;
            }
            if (i > 0) {
                return 1;
            }
            return 0;
        } else if (i == 0) {
            return 2;
        } else {
            return 3;
        }
    }

    public int getViewTypeCount() {
        return 4;
    }

    public void onClick(View view) {
        if (view != null) {
            int id = view.getId();
            if (id == j.ॱᐩ) {
                refreshExpandableStatus(view, 3);
            } else if (id == j.ᶡ) {
                refreshExpandableStatus(view, 1);
            } else if (id == j.יᐝ || id == j.ॱᐣ) {
                startDetailPage(view);
            } else if (id == j.ॱͺ) {
                goSettingDetail(view);
            } else if (id == j.ॱʽ) {
                openApp(view);
            } else if (id == j.ॱᕀ) {
                uninstallApp(view);
            } else if (id == j.ˊꜞ) {
                deleteDownload(view);
            }
        }
    }

    private void startDetailPage(View view) {
        if (view.getTag() instanceof InstallManagerCardBean) {
            long ॱ = ((InstallManagerCardBean) view.getTag()).ॱ();
            SessionDownloadTask ˎ = dvt.ˏ().ˎ(ॱ);
            if (ˎ == null) {
                Logger.ˎ(TAG, "not find task " + ॱ);
            } else if (ˎ.ˌ() == 9) {
                return;
            }
        }
        startDetailActivity(view);
    }

    private void startDetailActivity(View view) {
        BaseCardBean baseCardBean = null;
        if (view.getTag(j.יᐝ) instanceof BaseCardBean) {
            baseCardBean = (BaseCardBean) view.getTag(j.יᐝ);
            if (view.getTag(j.יᐝ) instanceof InstallManagerCardBean) {
                long ॱ = ((InstallManagerCardBean) view.getTag(j.יᐝ)).ॱ();
                SessionDownloadTask ˎ = dvt.ˏ().ˎ(ॱ);
                if (ˎ == null) {
                    Logger.ˎ(TAG, "not find task " + ॱ);
                } else if (ˎ.ˌ() == 9) {
                    return;
                }
            }
        } else if (view.getTag() instanceof BaseCardBean) {
            baseCardBean = (BaseCardBean) view.getTag();
        }
        if (baseCardBean != null) {
            dtb.ॱ().ॱ(this.mActivity, baseCardBean);
        }
    }

    private void goSettingDetail(View view) {
        Object obj = view.getTag().toString();
        if (!TextUtils.isEmpty(obj)) {
            NetWorkUtil.getWifiResId(this.mActivity, obj);
        }
    }

    private void uninstallApp(View view) {
        Object tag = view.getTag();
        if (tag instanceof ApkInstalledInfo) {
            ApkInstalledInfo apkInstalledInfo = (ApkInstalledInfo) tag;
            uninstallApp(this.mActivity, apkInstalledInfo.ʽ(), apkInstalledInfo.ॱ(), apkInstalledInfo.ˎ());
        }
    }

    private void deleteDownload(View view) {
        if (view.getTag() instanceof InstallManagerCardBean) {
            InstallManagerCardBean installManagerCardBean = (InstallManagerCardBean) view.getTag();
            if (this.mPackageState != null) {
                cnz ˏ = this.mPackageState.ˏ(installManagerCardBean.ॱـ());
                if (cnz.ˊ == ˏ || cnz.ˏ == ˏ) {
                    evk.ˏ(this.mActivity, n.ॱˋ, 0).ˋ();
                    return;
                }
            }
            setExpandPackageName(1, installManagerCardBean.ॱـ());
            ((cdf) cdb.ॱ(cdf.class)).ॱ(installManagerCardBean.ॱـ());
            if (dvt.ˏ().ˎ(installManagerCardBean.ॱ()) == null) {
                SessionDownloadTask sessionDownloadTask = new SessionDownloadTask();
                sessionDownloadTask.ʼ(installManagerCardBean.ॱـ());
                dvq.ˊ(this.mActivity, sessionDownloadTask, 3);
            }
            dsv.ˏ(installManagerCardBean.ॱـ());
            dtb.ॱ().ˏ(this.mActivity, installManagerCardBean);
            dtb.ॱ().ˏ(installManagerCardBean.ॱـ());
        }
    }

    private void openApp(View view) {
        Object tag = view.getTag();
        if (tag instanceof ApkInstalledInfo) {
            ApkInstalledInfo apkInstalledInfo = (ApkInstalledInfo) tag;
            if (apkInstalledInfo.ʽ()) {
                openApk(apkInstalledInfo.ॱ(), apkInstalledInfo.ˎ());
            } else {
                installBySubUserApk(apkInstalledInfo.ॱ());
            }
        }
    }

    private void refreshExpandableStatus(View view, int i) {
        String obj = view.getTag().toString();
        if (getExpandPackageName(i).equals(obj)) {
            setExpandPackageName(i, "");
        } else {
            setExpandPackageName(i, obj);
        }
        notifyDataSetChanged();
    }

    private void installBySubUserApk(String str) {
        int ˏ = etn.ˏ(0);
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (ˋ != null) {
            cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
            if (o_cnw != null) {
                o_cnw.ˏ(ContentManager.getInstant().getContext(), new o.cof.d().ˋ(str).ˊ(ˏ).ॱ(dwq.ˊ).ˎ());
                return;
            }
            Logger.e(TAG, "can not found IPackageInstaller Api");
            return;
        }
        Logger.e(TAG, "can not found PackageManager module");
    }

    private void openApk(String str, String str2) {
        dgh.ॱ(this.mActivity, "01060306", "02");
        if (str != null) {
            if (this.mActivity.getPackageName().equals(str)) {
                evk.ˋ(this.mActivity, this.mActivity.getResources().getString(dky.j.ˈॱ), 0).ˋ();
            } else {
                ced.ˎ(this.mActivity, str, str2);
            }
        }
        if (1 == dgm.ˎ((Activity) this.mActivity) && euf.ˎ().ˊ() && erw.ˏ(this.mActivity) && erw.ˏ(this.mActivity, "com.huawei.systemmanager")) {
            new Handler().postDelayed(new Runnable(this) {
                final /* synthetic */ InstalledListAdapter ˎ;

                {
                    this.ˎ = r1;
                }

                public void run() {
                    epw.ˎ(this.ˎ.mActivity);
                }
            }, 1000);
        }
    }

    public int getCount() {
        int i = 0;
        if (!this.requestInstalled.isEmpty()) {
            i = 0 + (this.requestInstalled.size() + 1);
        }
        if (this.installing.isEmpty() && this.downloading.isEmpty()) {
            return i;
        }
        return i + ((this.installing.size() + 1) + this.downloading.size());
    }

    public Object getItem(int i) {
        int size = this.installing.size() + this.downloading.size();
        if (size > 0) {
            size = i - size;
            if (size > 1) {
                return this.requestInstalled.get(size - 2);
            }
            if (size == 1 || i <= 0) {
                return null;
            }
            if (i - 1 < this.installing.size()) {
                return this.installing.get(i - 1);
            }
            return this.downloading.get((i - this.installing.size()) - 1);
        } else if (i != 0) {
            return this.requestInstalled.get(i - 1);
        } else {
            return null;
        }
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        int itemViewType = getItemViewType(i);
        if (itemViewType == 0) {
            return showInstallingTitle(view);
        }
        if (1 == itemViewType) {
            return showInstallingView(i, view);
        }
        if (2 != itemViewType) {
            return showInstalledView(i, view);
        }
        if (view != null && j.ͺˍ == view.getId()) {
            return view;
        }
        view = LayoutInflater.from(this.mActivity).inflate(h.ᶫ, null, false);
        azb.ˏ(view, j.ͺᐧ);
        TextView textView = (TextView) view.findViewById(j.ʼﾞ);
        if (textView == null) {
            return view;
        }
        textView.setText(ContentManager.getInstant().getContext().getString(n.ꓸˏ));
        return view;
    }

    private View showInstallingTitle(View view) {
        e eVar;
        int i = 0;
        e eVar2;
        if (view == null) {
            eVar2 = new e();
            view = createInstallingTitleView(eVar2);
            eVar = eVar2;
        } else if (view.getTag() instanceof e) {
            eVar = (e) view.getTag();
        } else {
            eVar2 = new e();
            view = createInstallingTitleView(eVar2);
            eVar = eVar2;
        }
        if (this.downloading.isEmpty()) {
            eVar.ˊ.setVisibility(8);
        } else {
            eVar.ˊ.setVisibility(0);
            if (dtb.ॱ().ˎ()) {
                eVar.ˊ.setText(n.ʻﾞ);
            } else if (dtb.ॱ().ʼ()) {
                eVar.ˊ.setText(n.ᐝ);
            } else {
                eVar.ˊ.setText(n.ˊՙ);
            }
            int size = this.downloading.size();
            for (SessionDownloadTask ˌ : this.downloading) {
                int i2;
                if (ˌ.ˌ() == 9) {
                    i2 = i + 1;
                } else {
                    i2 = i;
                }
                i = i2;
            }
            if (size == i) {
                eVar.ˊ.setVisibility(8);
            }
        }
        return view;
    }

    private View createInstallingTitleView(e eVar) {
        View inflate = LayoutInflater.from(this.mActivity).inflate(h.ॱㆍ, null, false);
        azb.ˏ(inflate, j.ᵕ);
        ((TextView) inflate.findViewById(j.ʼﾞ)).setText(ContentManager.getInstant().getContext().getString(n.ꓹ));
        eVar.ˊ = (TextView) inflate.findViewById(j.ʼꜟ);
        eVar.ˊ.setOnClickListener(new b());
        inflate.setTag(eVar);
        return inflate;
    }

    private View showInstallingView(int i, View view) {
        a aVar;
        Object item = getItem(i);
        a aVar2;
        if (view == null) {
            aVar2 = new a();
            view = createDownloadView(aVar2);
            aVar = aVar2;
        } else if (view.getTag() instanceof a) {
            aVar = (a) view.getTag();
        } else {
            aVar2 = new a();
            view = createDownloadView(aVar2);
            aVar = aVar2;
        }
        String str = "";
        if (item instanceof SessionDownloadTask) {
            SessionDownloadTask sessionDownloadTask = (SessionDownloadTask) item;
            String ˊˊ = sessionDownloadTask.ˊˊ();
            setDownloadDetail(sessionDownloadTask, aVar);
            str = ˊˊ;
        }
        if (str.equals(getExpandPackageName(1))) {
            LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
            layoutParams.setMarginStart(epv.ᐝ());
            dgh.ॱ(ContentManager.getInstant().getContext(), "070606", "06|" + this.shaUserId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.homeCountry);
            aVar.ˏ().setLayoutParams(layoutParams);
            aVar.ˎ().setVisibility(0);
            aVar.ʽ().setBackgroundResource(o.ewm.e.ॱʻ);
            aVar.ʻ().setBackgroundResource(o.ewm.e.ॱʻ);
            aVar.ͺ().setVisibility(0);
            aVar.ˋॱ().setVisibility(4);
        } else {
            aVar.ˎ().setVisibility(8);
            aVar.ʽ().setBackgroundResource(o.ewm.e.ˏˏ);
            aVar.ʻ().setBackgroundResource(o.ewm.e.ˏˏ);
            aVar.ͺ().setVisibility(4);
            aVar.ˋॱ().setVisibility(0);
        }
        if (!(this.requestInstalled.isEmpty() || 1 == getItemViewType(i + 1))) {
            aVar.ͺ().setVisibility(8);
            aVar.ˋॱ().setVisibility(8);
        }
        return view;
    }

    private void setDownloadDetail(SessionDownloadTask sessionDownloadTask, a aVar) {
        BaseDistCardBean installManagerCardBean = new InstallManagerCardBean();
        installManagerCardBean.ˏ(sessionDownloadTask.ʾ());
        installManagerCardBean.ˋᐝ(sessionDownloadTask.ˎˎ());
        installManagerCardBean.ˏॱ(sessionDownloadTask.ᐝ());
        installManagerCardBean.ˋ(sessionDownloadTask.ʿ());
        installManagerCardBean.ˏˎ(sessionDownloadTask.ˊˊ());
        installManagerCardBean.ॱ(sessionDownloadTask.ॱˊ());
        installManagerCardBean.ˉ(sessionDownloadTask.ॱˋ());
        installManagerCardBean.ॱᐝ(String.valueOf(sessionDownloadTask.ॱᐝ()));
        installManagerCardBean.ˎ(sessionDownloadTask.ˋ());
        aVar.ˋ().setTag(sessionDownloadTask.ˊˊ());
        aVar.ॱ().setTag(j.יᐝ, installManagerCardBean);
        aVar.ˏ().setTag(installManagerCardBean);
        setDownloadingAppIcon(sessionDownloadTask, aVar);
        setDownloadingAppName(sessionDownloadTask, aVar);
        aVar.ˏॱ().setParam(installManagerCardBean);
        aVar.ˏॱ().setVisibility(0);
        aVar.ˏॱ().setParam(installManagerCardBean);
        cke ॱ = aVar.ˏॱ().ॱ();
        installManagerCardBean.ˊ(getDldRecordIntro(sessionDownloadTask));
        if (ॱ == cke.ʼ) {
            aVar.ᐝ().setVisibility(0);
            aVar.ॱॱ().setVisibility(8);
            aVar.ʼ().setText(installManagerCardBean.O_());
            aVar.ˊॱ().setText(dwa.ˋ((long) sessionDownloadTask.ˉ()));
            return;
        }
        aVar.ᐝ().setVisibility(8);
        aVar.ॱॱ().setVisibility(0);
        if (ॱ == cke.ˋॱ) {
            CharSequence reserveDownloadContent = getReserveDownloadContent(ContentManager.getInstant().getContext());
            if (reserveDownloadContent != null) {
                CharSequence spannableString = new SpannableString(reserveDownloadContent);
                spannableString.setSpan(new ForegroundColorSpan(ContentManager.getInstant().getContext().getResources().getColor(o.ewm.c.ʼ)), 0, spannableString.length(), 33);
                aVar.ॱˊ().setText(spannableString);
                return;
            }
            return;
        }
        aVar.ॱˊ().setText(installManagerCardBean.O_());
    }

    private void setDownloadingAppIcon(SessionDownloadTask sessionDownloadTask, a aVar) {
        if (sessionDownloadTask.ˌ() == 9) {
            erm.ˏ().ˎ(o.ewm.e.ꓸ);
            erm.ˏ().ˋ(aVar.ॱ(), sessionDownloadTask.ˊˊ());
            return;
        }
        eqx.ˏ(aVar.ॱ(), sessionDownloadTask.ˎˎ(), "app_default_icon");
    }

    private void setDownloadingAppName(SessionDownloadTask sessionDownloadTask, a aVar) {
        int i = 0;
        String str = "";
        if (!TextUtils.isEmpty(sessionDownloadTask.ʿ())) {
            str = sessionDownloadTask.ʿ();
        }
        StringBuilder stringBuilder = new StringBuilder(str);
        if (sessionDownloadTask.ˌ() == 9) {
            str = sessionDownloadTask.ᐝᐝ();
            if (!dof.ˋ(str)) {
                String[] split = str.split(",");
                if (split.length > 0) {
                    try {
                        for (String parseInt : split) {
                            stringBuilder.append(HwAccountConstants.BLANK + bla.ˎ(ContentManager.getInstant().getContext(), sessionDownloadTask.ˊˊ(), Integer.parseInt(parseInt)));
                            if (i < split.length - 1) {
                                stringBuilder.append(",");
                            }
                            i++;
                        }
                    } catch (NumberFormatException e) {
                        Logger.e(TAG, "NumberFormatException");
                    }
                }
            }
        }
        aVar.ˊ().setText(stringBuilder.toString());
    }

    private String getReserveDownloadContent(Context context) {
        return NetWorkUtil.getWifiResId(context, n.ʽﾞ);
    }

    private View createDownloadView(a aVar) {
        View inflate = LayoutInflater.from(this.mActivity).inflate(h.ॱᶥ, null, false);
        aVar.ˊ((TextView) inflate.findViewById(j.ॱʼ));
        aVar.ˎ((MaskImageView) inflate.findViewById(j.יᐝ));
        azb.ॱ(aVar.ॱ());
        azb.ˋ(inflate, j.ᶥˊ);
        aVar.ॱ((TextView) inflate.findViewById(j.ˊˊ));
        aVar.ˏ((TextView) inflate.findViewById(j.ˍ));
        aVar.ˎ((TextView) inflate.findViewById(j.ـ));
        aVar.ˎ((LinearLayout) inflate.findViewById(j.ˌ));
        aVar.ॱ((LinearLayout) inflate.findViewById(j.ˎˎ));
        aVar.ˏ((RelativeLayout) inflate.findViewById(j.ᶡ));
        aVar.ˋ((DownloadButton) inflate.findViewById(j.ᶫॱ));
        aVar.ˊ((LinearLayout) inflate.findViewById(j.ᐝʼ));
        azb.ʻ(aVar.ˎ());
        aVar.ˏ(inflate.findViewById(j.ꓹ));
        aVar.ॱ(inflate.findViewById(j.ꜞˊ));
        aVar.ˋ(inflate.findViewById(j.ₗ));
        azb.ʻ(aVar.ˋॱ());
        aVar.ॱ((HwButton) inflate.findViewById(j.ˊꜞ));
        aVar.ᐝ().setVisibility(8);
        aVar.ॱॱ().setVisibility(8);
        aVar.ˎ(inflate.findViewById(j.ᕀ));
        ((RelativeLayout.LayoutParams) aVar.ˋॱ().getLayoutParams()).setMarginStart(epv.ᐝ());
        ((LinearLayout.LayoutParams) aVar.ͺ().getLayoutParams()).setMarginStart(epv.ᐝ());
        aVar.ॱ().setCornerType(2);
        aVar.ॱ().ॱ(1);
        aVar.ˋ().setOnClickListener(this);
        aVar.ॱ().setOnClickListener(this);
        aVar.ˏ().setOnClickListener(this);
        inflate.setTag(aVar);
        return inflate;
    }

    public String getDldRecordIntro(SessionDownloadTask sessionDownloadTask) {
        String str = "";
        Context ˋ = ContentManager.getInstant().getContext();
        if (sessionDownloadTask.ˈ() == -1) {
            return NetWorkUtil.getWifiResId(ˋ, n.ʽﾞ);
        }
        if (sessionDownloadTask.ˈ() == 6) {
            if (sessionDownloadTask.ᐝॱ() == 6 || sessionDownloadTask.ᐝॱ() == 5) {
                return ˋ.getResources().getString(n.ʻʿ);
            }
            return ˋ.getResources().getString(n.ᶫ);
        } else if (sessionDownloadTask.ˈ() == 0) {
            return ˋ.getResources().getString(n.ˏॱ);
        } else {
            if (sessionDownloadTask.ˈ() == 7) {
                return epw.ˊ(sessionDownloadTask.ˋˊ(), dkb.ˏ(sessionDownloadTask));
            }
            if (sessionDownloadTask.ˈ() == 5) {
                return ˋ.getResources().getString(n.ͺ);
            }
            return epw.ˊ(sessionDownloadTask.ˋˊ(), dkb.ˏ(sessionDownloadTask));
        }
    }

    private View showInstalledView(int i, View view) {
        c cVar;
        ApkInstalledInfo apkInstalledInfo = (ApkInstalledInfo) getItem(i);
        if (view == null) {
            cVar = new c();
            view = createInstalledView(cVar);
        } else {
            Object tag = view.getTag();
            if (tag instanceof c) {
                cVar = (c) tag;
            } else {
                cVar = new c();
                view = createInstalledView(cVar);
            }
        }
        if (apkInstalledInfo != null) {
            cVar.ॱ().setTag(apkInstalledInfo.ॱ());
            cVar.ॱ().setOnClickListener(this);
            mainLayoutLongClick(cVar, apkInstalledInfo);
            initButton(cVar, apkInstalledInfo);
            BaseCardBean baseCardBean = new BaseCardBean();
            baseCardBean.ˏˎ(apkInstalledInfo.ॱ());
            cVar.ˊ().ˊ().setTag(baseCardBean);
            initViewLabel(cVar.ˊ(), apkInstalledInfo);
            initExpandableRegion(cVar, apkInstalledInfo);
            if (getCount() - 1 == i) {
                cVar.ʼ().setVisibility(4);
                cVar.ʽ().setVisibility(4);
            }
        }
        return view;
    }

    private View createInstalledView(c cVar) {
        View inflate = LayoutInflater.from(this.mActivity).inflate(h.ॱˋ, null, false);
        cVar.ˊ().ˎ((MaskImageView) inflate.findViewById(j.ॱᐣ));
        azb.ॱ(cVar.ˊ().ˊ());
        azb.ˋ(inflate, j.ॱᐠ);
        cVar.ˊ().ˊ().setOnClickListener(this);
        ((MaskImageView) inflate.findViewById(j.ॱᐣ)).setCornerType(2);
        ((MaskImageView) inflate.findViewById(j.ॱᐣ)).ॱ(1);
        cVar.ˊ().ˎ((TextView) inflate.findViewById(j.ॱˮ));
        cVar.ˊ((LinearLayout) inflate.findViewById(j.ॱᐩ));
        cVar.ˏ(inflate.findViewById(j.ꜝॱ));
        cVar.ˎ(inflate.findViewById(j.ͺॱ));
        azb.ʻ(cVar.ʼ());
        ((RelativeLayout.LayoutParams) cVar.ʼ().getLayoutParams()).setMarginStart(epv.ᐝ());
        ((LinearLayout.LayoutParams) cVar.ʽ().getLayoutParams()).setMarginStart(epv.ᐝ());
        cVar.ˊ().ˊ((TextView) inflate.findViewById(j.ॱˡ));
        cVar.ˊ().ˋ((ImageView) inflate.findViewById(j.ॱʴ));
        cVar.ˊ().ˋ((TextView) inflate.findViewById(j.ॱᑊ));
        cVar.ˊ().ॱ((ImageView) inflate.findViewById(j.ॱᵣ));
        cVar.ˏ((HwButton) inflate.findViewById(j.ॱᕀ));
        cVar.ˋ((HwButton) inflate.findViewById(j.ॱͺ));
        cVar.ˏ((LinearLayout) inflate.findViewById(j.ˈﹳ));
        azb.ʻ(cVar.ˎ());
        cVar.ॱ((InstallButton) inflate.findViewById(j.ॱʽ));
        cVar.ᐝ().setOnClickListener(this);
        cVar.ˏ().setOnClickListener(this);
        cVar.ˋ().setOnClickListener(this);
        inflate.setTag(cVar);
        return inflate;
    }

    private void mainLayoutLongClick(c cVar, final ApkInstalledInfo apkInstalledInfo) {
        Object obj = null;
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (ˋ != null) {
            cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
            if (o_cnw != null) {
                obj = (o_cnw.ˏ(this.mActivity) & 2) != 0 ? 1 : null;
            }
        }
        if (obj == null || !this.supportBatchUninstall) {
            cVar.ॱ().setOnLongClickListener(null);
        } else {
            cVar.ॱ().setOnLongClickListener(new OnLongClickListener(this) {
                final /* synthetic */ InstalledListAdapter ˏ;

                public boolean onLongClick(View view) {
                    if (this.ˏ.iSelectAppAction != null) {
                        String ॱ;
                        long ˏ;
                        String str = "";
                        cnz o_cnz = cnz.ॱ;
                        if (this.ˏ.mPackageState != null) {
                            o_cnz = this.ˏ.mPackageState.ˎ(apkInstalledInfo.ॱ());
                        }
                        if (o_cnz == cnz.ॱ) {
                            ॱ = apkInstalledInfo.ॱ();
                            ˏ = apkInstalledInfo.ˏ();
                        } else {
                            ॱ = str;
                            ˏ = 0;
                        }
                        this.ˏ.iSelectAppAction.ˎ(ॱ, ˏ);
                    }
                    return true;
                }
            });
        }
    }

    private void initExpandableRegion(c cVar, ApkInstalledInfo apkInstalledInfo) {
        Context ˋ = ContentManager.getInstant().getContext();
        Drawable drawable;
        if (getExpandPackageName(3).equals(apkInstalledInfo.ॱ())) {
            LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
            int ᐝ = epv.ᐝ();
            int ॱ = ((azb.ॱ(ˋ) - ᐝ) - azb.ˏ(ˋ)) / 2;
            layoutParams.setMarginStart(ᐝ);
            cVar.ˋ().setLayoutParams(layoutParams);
            cVar.ˋ().setAllCaps(true);
            cVar.ˋ().setMaxWidth(ॱ);
            dgh.ॱ(ˋ, "070606", "03|" + this.shaUserId + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.homeCountry);
            cVar.ˎ().setVisibility(0);
            drawable = this.mActivity.getResources().getDrawable(o.ewm.e.ॱʻ);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            cVar.ˊ().ˋ().setCompoundDrawablePadding(this.compoundPadding);
            cVar.ˊ().ˎ().setBackground(drawable);
            if (!apkInstalledInfo.ʽ()) {
                cVar.ˊ().ˏ().setCompoundDrawablePadding(this.compoundPadding);
                cVar.ˊ().ʽ().setBackground(drawable);
            }
            cVar.ʼ().setVisibility(4);
            cVar.ʽ().setVisibility(0);
            return;
        }
        cVar.ˎ().setVisibility(8);
        drawable = this.mActivity.getResources().getDrawable(o.ewm.e.ˏˏ);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        cVar.ˊ().ˋ().setCompoundDrawablePadding(this.compoundPadding);
        cVar.ˊ().ˎ().setBackground(drawable);
        if (!apkInstalledInfo.ʽ()) {
            cVar.ˊ().ˏ().setCompoundDrawablePadding(this.compoundPadding);
            cVar.ˊ().ʽ().setBackground(drawable);
        }
        cVar.ʼ().setVisibility(0);
        cVar.ʽ().setVisibility(4);
    }

    public void initViewLabel(dtm o_dtm, ApkInstalledInfo apkInstalledInfo) {
        erm.ˏ().ˎ(o.ewm.e.ꓸ);
        erm.ˏ().ˋ(o_dtm.ˊ(), apkInstalledInfo.ॱ());
        o_dtm.ॱ().setText(apkInstalledInfo.ˎ());
        if (apkInstalledInfo.ʽ()) {
            o_dtm.ˏ().setText(apkInstalledInfo.ˊ());
            o_dtm.ˏ().setCompoundDrawables(null, null, null, null);
            o_dtm.ˏ().setTextColor(this.mActivity.getResources().getColor(o.ewm.c.ʻ));
            o_dtm.ˏ().setCompoundDrawables(this.transparentDrawable, this.transparentDrawable, this.transparentDrawable, this.transparentDrawable);
            o_dtm.ˏ().setCompoundDrawablePadding(0);
            o_dtm.ʽ().setVisibility(8);
            o_dtm.ˎ().setVisibility(0);
            if (dtg.ˎ(apkInstalledInfo.ʻ())) {
                o_dtm.ˋ().setText(DateUtils.formatDateTime(this.mActivity, apkInstalledInfo.ˋ(), 131092));
                o_dtm.ˋ().setVisibility(0);
                return;
            }
            o_dtm.ˋ().setVisibility(8);
            return;
        }
        o_dtm.ˏ().setText(this.mActivity.getString(n.ﹳˎ));
        o_dtm.ˏ().setAlpha(1.0f);
        o_dtm.ˏ().setTextColor(this.mActivity.getResources().getColor(o.ewm.c.ˊˋ));
        o_dtm.ˋ().setVisibility(8);
        o_dtm.ˎ().setVisibility(8);
    }

    private void initButton(c cVar, ApkInstalledInfo apkInstalledInfo) {
        cVar.ᐝ().setTag(apkInstalledInfo);
        cVar.ˏ().setTag(apkInstalledInfo.ॱ());
        cVar.ˋ().setTag(apkInstalledInfo);
        cnz o_cnz = cnz.ॱ;
        if (this.mPackageState != null) {
            o_cnz = this.mPackageState.ˏ(apkInstalledInfo.ॱ());
        }
        if (o_cnz == cnz.ʻ) {
            cVar.ˋ().setText(n.ˌ);
            cVar.ˋ().setClickable(false);
            cVar.ˋ().setEnabled(false);
        } else if (o_cnz == cnz.ॱॱ) {
            cVar.ˋ().setText(n.ˊˋ);
            cVar.ˋ().setClickable(false);
            cVar.ˋ().setEnabled(false);
        } else {
            cVar.ˋ().setText(n.ˋˑ);
            cVar.ˋ().setClickable(true);
            cVar.ˋ().setEnabled(true);
        }
        BaseDistCardBean installCardBean = new InstallCardBean();
        installCardBean.ˏˎ(apkInstalledInfo.ॱ());
        installCardBean.ॱ(apkInstalledInfo.ʽ());
        cVar.ᐝ().setParam(installCardBean);
        cVar.ᐝ().ॱ();
    }

    private void uninstallApp(final Context context, boolean z, final String str, final String str2) {
        if (this.dlg == null || !this.dlg.ˎ()) {
            this.dlg = BaseAlertDialog.ˋ(context, null, context.getString(n.ˊˊ, new Object[]{str2}));
            initDialogView(context, z, str2);
            this.dlg.ॱ();
            this.dlg.ॱ(BaseAlertDialog.a.ˋ, context.getString(n.ˉ));
            this.dlg.ˊ(new OnClickListener(this) {
                final /* synthetic */ InstalledListAdapter ˊ;

                public void onClick(View view) {
                    this.ˊ.dlg.ˏ();
                    boolean ˊ = ˊ(this.ˊ.dlg);
                    if (Logger.ˎ()) {
                        Logger.ˏ(InstalledListAdapter.TAG, "single uninstall onClick confirm,uninstallForAllUser is " + ˊ);
                    }
                    dgh.ॱ(context, "01060306", KeyAndValue.NUMBER_01);
                    int ˊ2 = etn.ˊ(0);
                    fhz ˋ = fho.ˏ().ˋ("PackageManager");
                    if (ˋ != null) {
                        cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
                        if (o_cnw != null) {
                            o_cnw.ˋ(ContentManager.getInstant().getContext(), new o.col.e().ॱ(str).ˏ(ˊ2).ॱ(ˊ).ॱ(new coe(str2)).ˏ(dwq.ˊ).ॱ());
                        } else {
                            Logger.e(InstalledListAdapter.TAG, "can not found IPackageInstaller Api");
                        }
                    } else {
                        Logger.e(InstalledListAdapter.TAG, "can not found PackageManager module");
                    }
                    ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(o.epx.a.ॱ));
                }

                private boolean ˊ(BaseAlertDialog o_ckr) {
                    Dialog ˋ = o_ckr.ˋ();
                    if (ˋ != null) {
                        CheckBox checkBox = (CheckBox) ˋ.findViewById(j.ᶫ);
                        if (checkBox != null) {
                            return checkBox.isChecked();
                        }
                    }
                    return false;
                }
            });
        }
    }

    private void initDialogView(Context context, final boolean z, String str) {
        eqh ˎ = eqh.ˎ();
        if (!ˎ.ˏ()) {
            View inflate = LayoutInflater.from(context).inflate(h.ˊˉ, null);
            ((TextView) inflate.findViewById(j.ˈﾟ)).setText(context.getString(n.ˊᐝ, new Object[]{str, context.getString(n.ˋˊ)}));
            ((TextView) inflate.findViewById(j.ˉʾ)).setText(context.getString(n.ˋᵔ, new Object[]{getMainUserName(ˎ, context)}));
            this.dlg.ˊ(inflate);
        } else if (ˎ.ॱ() != 1 || (!cep.ˏ() && isHasSubUser())) {
            String string;
            View inflate2 = LayoutInflater.from(context).inflate(h.ˊˑ, null);
            CheckBox checkBox = (CheckBox) inflate2.findViewById(j.ᶫ);
            checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(this) {
                final /* synthetic */ InstalledListAdapter ॱ;

                public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                    if (!z) {
                        this.ॱ.dlg.ˏ(z);
                    }
                }
            });
            TextView textView = (TextView) inflate2.findViewById(j.ˈﾟ);
            String str2 = "";
            if (z) {
                string = context.getString(n.ˋˊ);
            } else {
                checkBox.setChecked(true);
                this.dlg.ˏ(true);
                string = str2;
            }
            textView.setText(context.getString(n.ˊᐝ, new Object[]{str, string}));
            this.dlg.ˊ(inflate2);
        }
    }

    private String getMainUserName(eqh o_eqh, Context context) {
        String ˋ = o_eqh.ˋ(context, 0);
        if (TextUtils.isEmpty(ˋ)) {
            return dof.ʼ(ˋ);
        }
        return "\"" + ˋ + "\"";
    }

    public void onDestroy() {
        if (this.dlg != null) {
            this.dlg.ˏ();
        }
    }

    private boolean isHasSubUser() {
        if (CollectCheck.isEmpty(this.requestInstalled)) {
            return false;
        }
        for (ApkInstalledInfo ʽ : this.requestInstalled) {
            if (!ʽ.ʽ()) {
                return true;
            }
        }
        return false;
    }
}
